<template>
	<view class="container">
		<view class="list">
			<view class="item" v-for="item in list" @click="toUrl(`?activityId=${item.activityId}`)">
				<image :src="item.activityImg"></image>
				<view class="item-content">
					<view class="item-title">{{item.activityName}}</view>
					<view class="item-time">{{dayjs(item.startTime).format('YYYY[年]MM[月]DD[日]')}} ~ {{dayjs(item.endTime).format('YYYY[年]MM[月]DD[日]')}}</view>
				</view>
			</view>
		</view>
		<gzListNull :list="list"></gzListNull>
	</view>
	<!-- 授权登录弹窗 -->
	<gzLoginPopup ref="gzLoginPopupRef" v-model:isLogin="vdata.isLogin"></gzLoginPopup>
</template>

<script setup>
	import { onLoad } from '@dcloudio/uni-app';
	import { ref, reactive } from 'vue';
	import storageManage from '@/util/storageManage.js'
	import { $activityCodeList } from '@/http/apiManager.js';
	import useGetList from '@/hooks/useGetList.js'
	import appConfig from '@/config/appConfig.js'
	import { navigateTo } from '@/util/interceptors.js'
	import dayjs from 'dayjs'

	const vdata = reactive({
		isLogin: false, // 用户登录状态
		// 携带参数
		date: '',	// 日期
		activityChannelId: '',	// 渠道id
		from: '',	// 来源
	})
	const gzLoginPopupRef = ref()
	// 存储活动列表的数据
	const list = ref([])
	onLoad(({ channelCode, channelType, date, activityChannelId, from }) => {
		vdata.isLogin = storageManage.isLogin()
		vdata.date = date
		vdata.activityChannelId = activityChannelId
		vdata.from = from
		$activityCodeList({ channelCode, channelType }).then(res => {
			list.value = res.bizData.list
		})
	})
	/**
	 * 路由跳转
	 */
	const toUrl = (url) => {
		// 判断用户有没有登录
		if (!vdata.isLogin) {
			return gzLoginPopupRef.value.open() // 打开授权弹框
		}
		navigateTo({ url: url + `&date=${vdata.date}&activityChannelId=${vdata.activityChannelId}&from=${vdata.from}` })
	}
</script>

<style lang="less">
	.container {
		width: 100%;
		min-height: 100vh;
		padding: 24rpx;
		box-sizing: border-box;
		background-color: #F7F8FB;
		overflow: hidden;
		
		.list {
			display: flex;
			flex-direction: column;
			gap: 24rpx;

			.item {
				background-color: #fff;
				padding: 24rpx;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				gap: 24rpx;

				image {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
				}

				.item-content {
					flex-grow: 1;

					.item-title {
						font-size: 30rpx;
						color: #333;
						font-weight: bold;
					}

					.item-time {
						font-size: 24rpx;
						color: #999;
						margin-top: 10rpx;
					}
				}
			}
		}
	}
</style>